/*****************全局变量定义开始***************/
var protocol = location.protocol; // 获取http或https
var host = window.location.host; // 获取IP和端口号
var zxyPath = "/root_api/";
var contextPath = window.location.pathname.split('/')[1]; // 获取项目名
if(contextPath.indexOf(".") != -1 || contextPath.indexOf("?") != -1)
	contextPath = "";

//固定接口url,前后端分离需要配置
//protocol = "http:";
//host = "localhost:8080";
//数据接口web名称
//contextPath = "CDIsys_v3";

var basePath = protocol +"//"+host+"/";
//全局变量传递页面参数
var Temp_toparam = {};
//两种接口模式都支持 getdata.jsp便于调试
var proj_name = "getdata.do";//getdata.jsp "getdata.do"
//配置接口url
var baseUrl = basePath+contextPath+"/"+proj_name+"?sub_code=8A0731CC39614C90A5D474BC17253713&sub_usercode=414A6DB3BBE6419DA3768E6E25127310";
//业务接口url
var bizzUrl = basePath+contextPath+"/"+proj_name+"?sub_code=FF0731CC39614C90A5D474BC17253713&sub_usercode=114A6DB3BBE6419DA3768E6E25127310";
//全局变量
var session_id = "",login_id = "",nick_name="",s_title = "",user_main_id = "-1",role_id = 0,winWidth = 0, winHeight = 0,is_history_back = 0,iReturnUppLower=1;
//layer.open窗体序号
var ly_index;
//路由设置
var htmlRoute = [];
//[{"p_url":"p.vue","c_url":"c1.vue"},{"p_url":"p.vue","c_url":"c2.vue"}]
//js或css资源加载
var JSCSSRes = null;
/*****************全局变量定义结束***************/

/*****************业务通用函数开始***************/
//读取模板vue对象内容
function ReadCommonRes(objResult){
	//回调call_vue函数
	if(call_vue_funcName == "")
		callbackFuction("index_call_vue", objResult);
	else
		callbackFuction(call_vue_funcName, objResult);
}

//读取css或js资源内容
function ReadJSCSSRes(objResult){
	//动态加载js或css
	JSCSSRes = objResult;
	
	$.each(JSCSSRes.CSS_RESOURCE, function (i, obj) {
		loadStyles(obj.css_url);
	});
	$.each(JSCSSRes.JS_RESOURCE, function (i, obj) {
		loadScript(obj.js_url);
	});
}

//获取root路径
function getRootPath() {
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPath = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    if (baseUrl.indexOf(proj_name) != -1)
        return localhostPath + projectName;
    else
        return localhostPath;
}

//上传附件路径相对地址与配置参数UpLoad_File匹配，示例配置参数地址为d:\tomcat\webapps\CDIsys_v3\xxx\aaxxbb,
//则 return "/xxx/aaxxbb/";
function UpFilePath(){
	return "/file/upload/";
}

//页面初始化
function init_page() {
    //获取session_id
    session_id = localStorage.getItem('session_id');
    if (session_id == null)
        session_id = "";
    login_id = localStorage.getItem('login_id');
    if (login_id == null)
        login_id = "";
    nick_name = localStorage.getItem('nick_name');
    if (nick_name == null)
        nick_name = "";
    user_main_id = localStorage.getItem('user_main_id');
    if (user_main_id == null)
    	user_main_id = "";
    if (s_title == null)
    	s_title = "";
    role_id = localStorage.getItem('role_id');
    if (role_id == null)
        role_id = "";
    s_title = localStorage.getItem('s_title');
    $("title").html("欢迎使用"+s_title);
    //判断服务端session_id是否超时
    T01_SELSSS();
}

//获取IP及端口地址 
function getIP_Url() {
  return baseUrl.substring(0, baseUrl.indexOf("?"));
}

//用户登录信息结果
function T01_SELSSS_Result(input) {
	layer.close(ly_index);    
    var s_result = "";
    var error_desc = "";
    for (var key in input.T01_SELSSS[0]) {
        if (key == GetLowUpp('s_result')) {
            s_result = input.T01_SELSSS[0][GetLowUpp("s_result")];
            error_desc = input.T01_SELSSS[0][GetLowUpp("error_desc")];
        }
    }
    if (s_result != "1") {
    	window.location.href = getRootPath() + "/login.html";
    } 
    else 
    {
        //函数回调
        biz_start();
    }
}

//获取用户登录信息
function T01_SELSSS() {
	var inputdata = {param_name:"T01_SELSSS",session_id: session_id};
	get_ajax_staticurl(inputdata,"T01_SELSSS_Result");
}

//窗口大小
function getWindowSize() {
    //获取窗口宽度
    if (window.innerWidth) { //兼容火狐，谷歌,safari等浏览器
        winWidth = window.innerWidth;
    } else if ((document.body) && (document.body.clientWidth)) { //兼容IE浏览器
        winWidth = document.body.clientWidth;
    }

    //获取窗口高度
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
    }
}

//导出数据json格式与数据导入一致,跨业务系统数据复制 TB_NAME:表名,MAIN_IDS:对应选中MAIN_ID中间逗号隔开
function Load_out_table(TB_NAME,MAIN_IDS,DB_ID){
	var inputdata = {"param_name":"A01_OUTTAB","param_value1":TB_NAME,"param_value2":MAIN_IDS,"param_value3":DB_ID};
	get_ajax_baseurl(inputdata, "T00000_A01_OUTTAB_IN");
}

//导出数据json格式返回结果
function T00000_A01_OUTTAB_IN(input){
	layer.close(ly_index);
    //查询失败
    if (Call_OpeResult(input.A01_OUTTAB) == false)
        return false;
    else
    {
    	var content = JSON.stringify(input.A01_OUTTAB);
    	var blob = new Blob([content], {type: "text/plain;charset=utf-8"}); 
    	var tb_name = "";
    	for (var key in input.A01_OUTTAB){
    		tb_name = key.toString();
    		break;
    	}
    	var fileName = new Date().Format('yyyyMMddhhmmss')+tb_name+".json";    	
    	saveAs(blob, fileName);
    }
}

//通用子页面输入框赋值
function Com_edit_info(rowData,inputs,selects,textareas,RDA,RBC){
	$.each(selects, function (i, obj) {
		if(RDA != RBC && typeof(eval(RDA+"_ary_"+obj.id.toString().replace(RBC+"_",""))) == "object")
		{
			$.each(eval(RDA+"_ary_"+obj.id.toString().replace(RBC+"_","")), function (inx, obj_sub) {
				addOptionValue($(obj).id,obj_sub[GetLowUpp("main_id")],obj_sub[GetLowUpp("cn_name")]);
			});
		}
	});
	Object.keys(rowData).forEach(function (key) {
		$.each(inputs, function (i, obj) {
			if(obj.id.toUpperCase() == (RBC+"_"+key).toUpperCase()) {
				if(typeof(rowData[key]) == "string")
				{
					var temV = s_decode(rowData[key]);
					if(Judge_DateTime(temV))
						$(obj).val(temV.substring(0,19));
					else
						$(obj).val(temV);
				}
				else
				{
					$(obj).val(rowData[key]);
				}
			}
			else if(RDA != RBC && obj.id.toUpperCase() == (RBC+"_find_"+key+"_cn_name").toUpperCase()){
				if(RDA.substring(1,RDA.length - 1) != RBC.substring(1,RBC.length - 1)){
					$.each(eval(RBC+"_ary_"+key), function (jindex, obj2) {
						if(obj2[GetLowUpp("main_id")] == rowData[key]){
							$("#"+RBC+"_DataModal").find('[id="'+RBC+"_"+("find_"+key+"_cn_name")+'"]').val(s_decode(obj2[GetLowUpp("cn_name")]));
						}
					});
				}
				else{
					if(rowData.hasOwnProperty(key+"_FIND_CN_NAME")){
						$("#"+RBC+"_DataModal").find('[id="'+RBC+"_"+("find_"+key+"_cn_name")+'"]').val(s_decode(rowData[GetLowUpp(key)+"_FIND_CN_NAME"]));
						//附件div显示
						$("#"+RBC+"_"+key+"_div").html(set_file_show(s_decode(rowData[GetLowUpp(key)+"_FIND_CN_NAME"]),null,0));
						
					}
					else{
						$.each(eval(RDA+"_ary_"+key), function (jindex, obj2) {
							if(obj2[GetLowUpp("main_id")] == rowData[key]){
								$("#"+RBC+"_DataModal").find('[id="'+RBC+"_"+("find_"+key+"_cn_name")+'"]').val(s_decode(obj2[GetLowUpp("cn_name")]));
							}
						});
					}
				}
			}
			else if(rowData.hasOwnProperty(obj.id.toUpperCase().replace(RDA+"_",""))){
				var temK2 = obj.id.toUpperCase().replace(RDA+"_","");
				if(typeof(rowData[temK2]) == "string")
				{
					var temV = s_decode(rowData[temK2]);
					if(Judge_DateTime(temV))
						$(obj).val(temV.substring(0,19));
					else
						$(obj).val(temV);
				}
				else
				{
					$(obj).val(rowData[temK2]);
				}
			}
		});
		$.each(selects, function (i, obj) {
			if (obj.id.toUpperCase() == (RBC+"_"+key).toUpperCase()) {
				$(obj).val(s_decode(rowData[key]));
			}
			else if(rowData.hasOwnProperty(obj.id.toUpperCase().replace(RDA+"_",""))){
				var temK2 = obj.id.toUpperCase().replace(RDA+"_","");
				$(obj).val(s_decode(rowData[temK2]));
			}
		});
		$.each(textareas, function (i, obj) {
			if (obj.id.toUpperCase() == (RBC+"_"+key).toUpperCase()) {
				if(typeof(rowData[key]) == "string")
				{
					$(obj).val(s_decode(rowData[key]));
				}
				else
				{
					$(obj).val(rowData[key]);
				}
			}
			else if(rowData.hasOwnProperty(obj.id.toUpperCase().replace(RDA+"_",""))){
				var temK2 = obj.id.toUpperCase().replace(RDA+"_","");
				if(typeof(rowData[temK2]) == "string")
				{
					$(obj).val(s_decode(rowData[temK2]));
				}
				else
				{
					$(obj).val(rowData[temK2]);
				}
			}
		});
	});
}

//附件上传
function get_ajax_upload(formData,param_v, inputjsonpCallBack) {
    ly_index = layer.load();        
    $.ajax({
    	url:basePath+contextPath+"/uploadFile?param_name=upLoadFile&session_id="+session_id+param_v,
        type: "POST",
        data: formData,
        dataType: 'json',
        processData: false, // 不处理数据
        contentType: false, // 不设置内容类型
        enctype: 'multipart/form-data',
        success: function (input) {
        	layer.close(ly_index);
        	callbackFuction(inputjsonpCallBack, input);
        },
        error: function () {
            layer.close(ly_index);
            swal({
                title: "告警",
                text: "网络异常或系统故障，请刷新页面！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "刷新",
                closeOnConfirm: false
            },
                function () {
                layer.close(ly_index);
                window.location.reload();
            });
        },
        // 请求完成后的回调函数 (请求成功或失败之后均调用)
        complete: function (XMLHttpRequest, textStatus) {
            $("#doing").empty();
            $("#doing").attr("style", "display:none");
        }
    });
}

//标准静态配置库数据提交
function get_ajax_staticurl(inputData, inputjsonpCallBack) {
	if(!inputData.hasOwnProperty("login_id")){
		inputData["login_id"] = login_id;
	}
	if(!inputData.hasOwnProperty("session_id")){
		inputData["session_id"] = session_id;
	}
    if (is_history_back == 0) {
    	//console.log("接口数据结开始时间"+new Date().Format('yyyy-MM-dd hh:mm:ss SSS')+"=>"+inputData.param_name);
        ly_index = layer.load();
        $.ajax({
            type: "POST",
            async: false,
            url: baseUrl,
            data: inputData,
            //跨域请求的URL
            dataType: "jsonp",
            jsonp: "jsoncallback",
            jsonpCallback: inputjsonpCallBack,
            success: function (data) {
            	//console.log("接口数据结束时间"+new Date().Format('yyyy-MM-dd hh:mm:ss SSS')+"=>"+inputData.param_name);
            },
            error: function () {
                layer.close(ly_index);
                swal({
                    title: "告警",
                    text: "网络异常或系统故障，请刷新页面！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "刷新",
                    closeOnConfirm: false
                },
                    function () {
                    layer.close(ly_index);
                    window.location.reload();
                });
            },
            // 请求完成后的回调函数 (请求成功或失败之后均调用)
            complete: function (XMLHttpRequest, textStatus) {
                $("#doing").empty();
                $("#doing").attr("style", "display:none");
            }
        });
    } 
    else if (is_history_back == 1) {
        var storage = localStorage.getItem(getPageUrl() + inputjsonpCallBack.toString());
        if (storage != null) {
            ly_index = layer.load();
            var data = JSON.parse(storage);
            callbackFuction(inputjsonpCallBack, data);
        }
    }
}

//标准业务库数据提交
function get_ajax_baseurl(inputData, inputjsonpCallBack) {
	if(!inputData.hasOwnProperty("login_id")){
		inputData["login_id"] = login_id;
	}
	if(!inputData.hasOwnProperty("session_id")){
		inputData["session_id"] = session_id;
	}
    if (is_history_back == 0) {
        ly_index = layer.load();
        //console.log("接口数据开始时间"+new Date().Format('yyyy-MM-dd hh:mm:ss SSS')+"=>"+inputData.param_name);
        $.ajax({
            type: "POST",
            async: false,
            url: bizzUrl,
            data: inputData,
            //跨域请求的URL
            dataType: "jsonp",
            jsonp: "jsoncallback",
            jsonpCallback: inputjsonpCallBack,
            success: function (data) {
            	//console.log("接口数据结束时间"+new Date().Format('yyyy-MM-dd hh:mm:ss SSS')+"=>"+inputData.param_name);
            },
            error: function () {
                layer.close(ly_index);
                swal({
                    title: "告警",
                    text: "网络异常或系统故障，请刷新页面！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "刷新",
                    closeOnConfirm: false
                },
                    function () {
                    layer.close(ly_index);
                    window.location.reload();
                });
            },
            // 请求完成后的回调函数 (请求成功或失败之后均调用)
            complete: function (XMLHttpRequest, textStatus) {
                $("#doing").empty();
                $("#doing").attr("style", "display:none");
            }
        });
    } 
    else if (is_history_back == 1) {
        var storage = localStorage.getItem(getPageUrl() + inputjsonpCallBack.toString());
        if (storage != null) {
            ly_index = layer.load();
            var data = JSON.parse(storage);
            callbackFuction(inputjsonpCallBack, data);
        }
    }
}

//查询成功或失败
function Call_QryResult(inputValue){
	layer.close(ly_index);
	var s_result = "";
    var error_desc = "";
    for (var key in inputValue[0]) {
        if (key == GetLowUpp('s_result')) {
            s_result = inputValue[0][GetLowUpp("s_result")];
            error_desc = s_decode(inputValue[0][GetLowUpp("error_desc")]);
        }
    }
    if (s_result == "0") {
		layer.close(ly_index);
        swal("数据读取失败!", "失败原因:" + error_desc, "warning");
		return false;
    }
    else
    	return true;
}

//操作成功或失败
function Call_OpeResult(inputValue){
	layer.close(ly_index);
	var s_result = "1";
    var error_desc = "";
    for (var key in inputValue[0]) {
        if (key == GetLowUpp('s_result')) {
            s_result = inputValue[0][GetLowUpp("s_result")];
            error_desc = s_decode(inputValue[0][GetLowUpp("error_desc")]);
        }
    }
    if (s_result == "0") {
        swal("数据读取失败!", "失败原因:" + error_desc, "warning");
		return false;
    }
    else
    {
    	swal("操作成功!", error_desc, "success");
    	return true;
    }
}

//启用禁用
function get_s_state(value, row, index) {
    if (value == "1")
        return "启用";
    else if (value == "0")
        return "<font color='red'>禁用</font>";
}

//启用禁用
function get_is_ava(value, row, index) {
    if (value == "1")
        return "启用";
    else if (value == "0")
        return "<font color='red'>禁用</font>";
}

//动态加载js脚本文件 无任何返回动作
function loadScript_nofun(url) {
	var temUrl = "";
	if(url.lastIndexOf(".vue") != -1)
		if(url.indexOf("?") == -1 && url.lastIndexOf(".vue") == url.length - 4)
			//temUrl = url;
			temUrl = basePath+contextPath+zxyPath+ url;
		else if(url.indexOf("?") != -1 && url.lastIndexOf(".vue") == url.indexOf("?") - 4)
			//temUrl = url;
			temUrl = basePath+contextPath+zxyPath+ url;
		else
			temUrl = url
	else
		temUrl = url;
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = temUrl;
	document.body.appendChild(script);
}

//返回vue文件或html文件名
function RetVueOrHtml(url){
	if(url.lastIndexOf(".vue") != -1)
		if(url.indexOf("?") == -1 && url.lastIndexOf(".vue") == url.length - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else if(url.indexOf("?") != -1 && url.lastIndexOf(".vue") == url.indexOf("?") - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else
			temUrl = url
	else
		temUrl = url;
}

//判断vue文件或html文件
function IsVueOrHml(url){
	if(url.lastIndexOf(".vue") != -1)
		return 1;
	else if(url.lastIndexOf(".html") != -1)
		return 2;
	else
		return 3;
}

//动态加载js脚本文件 含回调函数
function loadScript_noparam(url,callback) {
	var temUrl = "";
	if(url.lastIndexOf(".vue") != -1)
		if(url.indexOf("?") == -1 && url.lastIndexOf(".vue") == url.length - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else if(url.indexOf("?") != -1 && url.lastIndexOf(".vue") == url.indexOf("?") - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else
			temUrl = url
	else
		temUrl = url;	
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = temUrl;
	if (script.addEventListener) {
		script.addEventListener('load', function () {
			eval(callback + "()");
		 }, false);
	} else if (script.attachEvent) {
		script.attachEvent('onreadystatechange', function () {
			var target = window.event.srcElement;
			if (target.readyState == 'loaded') {
				eval(callback + "()");
			}
		});
	}
	document.body.appendChild(script);
}

//动态加载js脚本文件 含回调函数及参数
function loadScript_hasparam(url,callback,data) {
	var temUrl = "";
	if(url.lastIndexOf(".vue") != -1)
		if(url.indexOf("?") == -1 && url.lastIndexOf(".vue") == url.length - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else if(url.indexOf("?") != -1 && url.lastIndexOf(".vue") == url.indexOf("?") - 4)
			temUrl = url;//temUrl = "root_api/"+ url;
		else
			temUrl = url
	else
		temUrl = url;	
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = url;
	if (script.addEventListener) {
		script.addEventListener('load', function () {
			callbackFuction(callback,data);
		 }, false);
	} else if (script.attachEvent) {
		script.attachEvent('onreadystatechange', function () {
			var target = window.event.srcElement;
			if (target.readyState == 'loaded') {
				callbackFuction(callback,data);
			}
		});
	}
	document.body.appendChild(script);
}

//加载子vue文件及回调函数
function loadHtmlSubVueFun(sub_vue,fun_name){
	var ahref = window.document.location.pathname.replace("/","")
	var temRoute = {"p_url":ahref,"c_url":sub_vue};
	var htmlSetHasSub = false;
	$.each(htmlRoute, function (i, obj) {
		if(CompareJsonObj(obj,temRoute) == true){
			htmlSetHasSub = true;
		}
	});
	if(htmlSetHasSub == false){
		//添加路由
    	htmlRoute.push(temRoute);		
		call_vue_funcName = fun_name;
		
//		if(index_suburl != "")
//			loadStyles(index_suburl+".css");
//		//移除上个页面所有css
//		$.each(previous_subhtml, function (i, obj) {
//			if(obj != "" && obj != index_subname)
//				removejscssfile(obj,"css");
//		});
		
		loadScript_nofun(sub_vue+"?callback=ReadCommonRes");
	}
	return htmlSetHasSub
}

//特殊字符串数据解码
function set_s_decode(value, row, index) {
    return s_decode(value.toString());
}

//时间数据解码
function set_time_decode(value, row, index) {
	if(value == "")
		return "";
    var timeResult = s_decode(value.toString());
    timeResult = timeResult.replace("T"," ");
    return new Date(timeResult).Format('yyyy-MM-dd hh:mm:ss');
}

//清除 查找框
function clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//加载子vue文件无回调函数
function loadHtmlSubVue(sub_vue){
	var ahref = window.document.location.pathname.replace("/","")
	var upd_pwd_temRoute = {"p_url":ahref,"c_url":index_subhtml};
	var htmlSetHasSub = false;
	$.each(htmlRoute, function (i, obj) {
		if(CompareJsonObj(obj,upd_pwd_temRoute) == true){
			htmlSetHasSub = true;
		}
	});
	if(htmlSetHasSub == false){
		//添加路由
    	htmlRoute.push(upd_pwd_temRoute);
		call_vue_funcName = "";
		loadScript_nofun(sub_vue+"?callback=ReadCommonRes");
	}
	return htmlSetHasSub
}

//加载左侧不显示菜单
function Add_No_Show_Menu(temindex_subhtml,inputrandom,objtoparam,objtitle){
	if($("#side-menu").find("[attRandom=\""+inputrandom+"\"]").length == 0){
		if($("#side-menu").find("[id=\"No_Show\"]").length == 0){
			var divGroup = "<li class=\"active\" id=\"No_Show\" style=\"display:none\">"
			 +"		<a href=\"#\">"
			 +"			<i class=\"fa fa-gear\"></i>"
			 +"			<span class=\"nav-label\">隐藏菜单</span>"
			 +"			<span class=\"fa arrow\"></span>"
			 +"		</a>"
			 +"		<ul class=\"nav nav-second-level collapse in\" id =\"No_Show_menu\">"
			 +"		</ul>"
			 +"</li>"
			 $("#side-menu").append(divGroup);
		}
		var divMenuInfo = "<li>" + "<a class=\"J_menuItem\" href=\""+temindex_subhtml+"\" attRandom=\""
						+inputrandom+"\" data-index=\""+($(".J_menuItem").length).toString()+"\">"+objtitle+"</a></li>";
		$("#No_Show_menu").append(divMenuInfo);
		loadScript_nofun("js/contabs.min.js");
		$("#side-menu").find("[attRandom=\""+inputrandom+"\"]").on("click",c);		
	}
	//传递参数
	var temDiv = inputrandom+"_div"+$("#side-menu").find("[attRandom=\""+inputrandom+"\"]").attr("data-index");
	Temp_toparam = objtoparam;
	if($("#"+temDiv).length > 0){
		//点击左侧菜单
		$("#side-menu").find("[attRandom=\""+inputrandom+"\"]").click();
		eval(inputrandom+"_param = {}");
		for(var key in objtoparam)
			eval(inputrandom+"_param['"+key+"'] = '"+objtoparam[key]+"'");
		//参数传递并赋值
		eval(inputrandom+"_param_set()");
		var tbName = "";
		if(index_subhtml.indexOf("/") == -1)
			tbName = index_subhtml.substring(0,index_subhtml.indexOf(".vue"));
		else
			tbName = index_subhtml.substring(index_subhtml.lastIndexOf("/")+1,index_subhtml.indexOf(".vue"));
		//初始化子页面
		eval(inputrandom+"_init_"+tbName+"()");
		Temp_toparam = {};
	}
	else{
		//点击左侧菜单
		$("#side-menu").find("[attRandom=\""+inputrandom+"\"]").click();
	}
}

//附件显示
function set_file_show(value, row, index){
	var attF = value.substring(value.indexOf(".")+1,value.length).toUpperCase();
	var vt = basePath+contextPath+UpFilePath()+value
	if(attF == "JPG" || attF == "BMP"
		|| attF == "JPG" || attF == "JPEG"
		|| attF == "PNG" || attF == "GIF")
	{
		var vt = basePath+contextPath+UpFilePath()+value
		return "<a href=\""+vt+"\" target=\"_blank\"><img src=\""+vt+"\" style=\"width:100px\"/></a>";
	}
	else
	{
		return "<a href=\""+vt+"\" target=\"_blank\">"+value+"</a>";
	}
}
/*****************业务通用函数结束***************/


/*****************js通用函数开始***************/
//获取当前页面名称
function getPageUrl(){
	 var str = window.location.pathname;
	 str = str.substr(str.lastIndexOf('/', str.lastIndexOf('/') - 1) + 1);
	 str = str.substr(0,str.lastIndexOf('.html', str.lastIndexOf('.html')));
	 str = str.replaceAll("/","_")+"_";
	 return str;
}

function get_long(){
	return new Date().getTime().toString();
}

//获取页面传递的参数
function getUrlParam(k) {
	 var regExp = new RegExp('([?]|&)' + k + '=([^&]*)(&|$)');
	 var result = window.location.href.match(regExp);
	 if (result) {
	     return decodeURIComponent(result[2]);
	 } else {
	     return null;
	 }
}

//大小写转换
function GetLowUpp(inputValue){
    if(iReturnUppLower == 1)
        return inputValue.toUpperCase();
    else if(iReturnUppLower == 2)
        return inputValue.toLowerCase();
    else
        return inputValue;
}

//时间格式化
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S+": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//时间格式化2
function dateFmt(fmt, date) { //author: meizz
    var o = {
        "M+": date.getMonth() + 1, //月份
        "d+": date.getDate(), //日
        "h+": date.getHours(), //小时
        "m+": date.getMinutes(), //分
        "s+": date.getSeconds(), //秒
        "q+": Math.floor((date.getMonth() + 3) / 3), //季度
        "S+": date.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//特殊字符解析
function js_decode(s) {
	if(typeof(s) != "undefined" && s != "")
	{
	    while (s.indexOf('+') >= 0)
	        s = s.replace('+', '%20');
	}
    return s;
}

//编码
function s_encode(s_result) {
    //对应后台解码 python encodeURIComponent(s_result);
	//对应后台解码java   encodeURIComponent(s_result).replace(/%20/g,"+");
    return encodeURIComponent(s_result);
}

//解码
function s_decode(s_result) {
	if(s_result == "")
		return "";
	var vR = js_decode(s_result);
	if(vR != "\%")
		return decodeURIComponent(vR);
	return vR;
}

//获取IP地址
function getIP_Addr() {
    var a = window.location.href.replace("http://", "");
    var a_ary = a.substring(0, a.indexOf("/")).split(':');
    return a_ary[0];
}

//随机码GUID
function GUID() {
    this.date = new Date();
    /* 判断是否初始化过，如果初始化过以下代码，则以下代码将不再执行，实际中只执行一次 */
    if (typeof this.newGUID != 'function') {
        /* 生成GUID码 */
        GUID.prototype.newGUID = function () {
            this.date = new Date();
            var guidStr = '';
            sexadecimalDate = this.hexadecimal(this.getGUIDDate(), 16);
            sexadecimalTime = this.hexadecimal(this.getGUIDTime(), 16);
            for (var i = 0; i < 9; i++) {
                guidStr += Math.floor(Math.random() * 16).toString(16);
            }
            guidStr += sexadecimalDate;
            guidStr += sexadecimalTime;
            while (guidStr.length < 32) {
                guidStr += Math.floor(Math.random() * 16).toString(16);
            }
            return this.formatGUID(guidStr);
        }
        /* * 功能：获取当前日期的GUID格式，即8位数的日期：19700101 * 返回值：返回GUID日期格式的字条串 */
        GUID.prototype.getGUIDDate = function () {
            return this.date.getFullYear() + this.addZero(this.date.getMonth() + 1) + this.addZero(this.date.getDay());
        }
        /* * 功能：获取当前时间的GUID格式，即8位数的时间，包括毫秒，毫秒为2位数：12300933 * 返回值：返回GUID日期格式的字条串 */
        GUID.prototype.getGUIDTime = function () {
            return this.addZero(this.date.getHours()) + this.addZero(this.date.getMinutes()) + this.addZero(this.date.getSeconds()) + this.addZero(parseInt(this.date.getMilliseconds() / 10));
        }
        /* * 功能: 为一位数的正整数前面添加0，如果是可以转成非NaN数字的字符串也可以实现 * 参数: 参数表示准备再前面添加0的数字或可以转换成数字的字符串 * 返回值: 如果符合条件，返回添加0后的字条串类型，否则返回自身的字符串 */
        GUID.prototype.addZero = function (num) {
            if (Number(num).toString() != 'NaN' && num >= 0 && num < 10) {
                return '0' + Math.floor(num);
            } else {
                return num.toString();
            }
        }
        /*  * 功能：将y进制的数值，转换为x进制的数值 * 参数：第1个参数表示欲转换的数值；第2个参数表示欲转换的进制；第3个参数可选，表示当前的进制数，如不写则为10 * 返回值：返回转换后的字符串 */
        GUID.prototype.hexadecimal = function (num, x, y) {
            if (y != undefined) {
                return parseInt(num.toString(), y).toString(x);
            } else {
                return parseInt(num.toString()).toString(x);
            }
        }
        /* * 功能：格式化32位的字符串为GUID模式的字符串 * 参数：第1个参数表示32位的字符串 * 返回值：标准GUID格式的字符串 */
        GUID.prototype.formatGUID = function (guidStr) {
            var str1 = guidStr.slice(0, 8),
            str2 = guidStr.slice(8, 12),
            str3 = guidStr.slice(12, 16),
            str4 = guidStr.slice(16, 20),
            str5 = guidStr.slice(20);
            return guidStr.toUpperCase(); //(str1 + str2 + str3 + str4 + str5).toUpperCase();
        }
    }
}

//校验是否为时间格式
function Judge_DateTime(inputDTime){
	var DATE_FORMAT = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1} ([0-2][0-9]):([0-5][0-9]):([0-5][0-9])$/;
	if(inputDTime.length < 19)
		return false;
	else if(DATE_FORMAT.test(inputDTime.substring(0,19))){
		return true;
	}
	else{
		return false;
	}
}

//时间或日期相加
function DateAdd(interval, number, date) {
    switch (interval) {
    case "y": {
            date.setFullYear(date.getFullYear() + number);
            return date;
            break;
        }
    case "q": {
            date.setMonth(date.getMonth() + number * 3);
            return date;
            break;
        }
    case "M": {
            date.setMonth(date.getMonth() + number);
            return date;
            break;
        }
    case "w": {
            date.setDate(date.getDate() + number * 7);
            return date;
            break;
        }
    case "d": {
            date.setDate(date.getDate() + number);
            return date;
            break;
        }
    case "H": {
            date.setHours(date.getHours() + number);
            return date;
            break;
        }
    case "m": {
            date.setMinutes(date.getMinutes() + number);
            return date;
            break;
        }
    case "s": {
            date.setSeconds(date.getSeconds() + number);
            return date;
            break;
        }
    default: {
            date.setDate(date.getDate() + number);
            return date;
            break;
        }
    }
}

//回调函数,不带返回值
function callbackFuction(callback, data){
    eval(callback + "(data)");
}

//回调函数，带返回值
function callbackFuctionRt(callback, data) {
  return eval(callback + "(data)");
}

//以下3个方法为列表处理通用方法
function isExistOption(id, value) {
    var isExist = false;
    var count = $('#' + id).find('option').length;
    for (var i = 0; i < count; i++) {
        if ($('#' + id).get(0).options[i].value == value) {
            isExist = true;
            break;
        }
    }
    return isExist;
}

//添加select中某个option
function addOptionValue(id, value, text) {
    if (!isExistOption(id, value)) {
        $('#' + id).append("<option value='" + value + "'>" + text + "</option>");
    }
}

//删除select中某个option
function delOptionValue(id, value) {
    if (isExistOption(id, value)) {
        $("#" + id + " option[value=" + value + "]").remove();
    }
}

//判断是否object
function isObj(object) {
    return object && typeof(object) == 'object' && Object.prototype.toString.call(object).toLowerCase() == "[object object]";
}
 
//判断是否array
function isArray(object) {
    return object && typeof(object) == 'object' && object.constructor == Array;
}

//获取长度
function getLength(object) {
    var count = 0;
    for(var i in object) 
    	count++;
    return count;
}

//比较objA 和objB 2个json对象
function CompareJsonObj(objA, objB) {
    if(!isObj(objA) || !isObj(objB)) return false; //判断类型是否正确
    if(getLength(objA) != getLength(objB)) return false; //判断长度是否一致
    return CompareObj(objA, objB, true); //默认为true
}

//循环递归比较objA 和objB 2个json对象
function CompareObj(objA, objB, flag) {
	if(getLength(objA) != getLength(objB)) return false;
    for(var key in objA) {
        if(!flag) //flag为false，则跳出整个循环
            break;
        if(!objB.hasOwnProperty(key)) {//是否有自身属性，而不是继承的属性
            flag = false;
            break;
        }
        if(!isArray(objA[key])) { //子级不是数组时,比较属性值        	
        	if (isObj(objA[key])) {
        		if (isObj(objB[key])) {
        			if(!flag) //这里跳出循环是为了不让递归继续
                        break;
        			flag = CompareObj(objA[key], objB[key], flag);
        		} else {
        			flag = false;
                    break;
        		}
        	} else {
        		if(String(objB[key]) != String(objA[key])) { //排除数字比较的类型差异
            		flag = false;
                    break;
                }
        	}
        } else {
            if(!isArray(objB[key])) {
                flag = false;
                break;
            }
            var oA = objA[key],
                oB = objB[key];
            if(oA.length != oB.length) {
                flag = false;
                break;
            }
            for(var k in oA) {
                if(!flag) //这里跳出循环是为了不让递归继续
                    break;
                flag = CompareObj(oA[k], oB[k], flag);
            }
        }
    }
    return flag;
}

// 动态加载css文件
function loadStyles(url) {
	var link = document.createElement("link");
	link.type = "text/css";
	link.rel = "stylesheet";
	link.href = url;
	document.getElementsByTagName("head")[0].appendChild(link);
}

//动态加载js脚本文件
function loadScript(url) {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = url;
	document.body.appendChild(script);
}

//jsonArray 将属性名称大写转小写,将属性值解码
function formatTree(inputValue) {
	var objResult = [];	
	$.each(inputValue, function (i, obj) {
		var temtag = {};
		for (var i in obj) {
			if(parseInt(obj[i]) % 1 == 0)
				temtag[i.toLowerCase()] = parseInt(obj[i]);
			else
				temtag[i.toLowerCase()] = s_decode(obj[i]);
		}
		objResult.push(temtag)
	});
	return objResult;
};

//判断某js是否已加载
function IsLoadScript(objJsName){
	$("script").each(function(i,e){
		if(e.src.indexOf(objJsName)>=0){//test.js
			return true;
		}
	});
	return false;
}

//判断某一js或CSS是否加载
function IsLoadJSCSS(temJS){
	$("script").each(function(i,e){
		if(e.src.indexOf(temJS)>=0){
			return true;
		}
	});
	
	$("link").each(function(i,e){
		if(e.href.indexOf(temJS)>=0){
			return true;
		}
	});
	return false;
}

//json数据key转换
function JSONkeyReplace(inputValue,OldKey,NewKey){
	var objResult = [];	
	$.each(inputValue, function (i, obj) {
		var temtag = {};
		for (var i in obj) {
			if(i == OldKey)
				temtag[NewKey] = obj[i];
			else
				temtag[i] = obj[i];
		}
		objResult.push(temtag)
	});
	return objResult;
}

//树形节点递归展开,父子节点id为整数
function formatSubTree(ary,c_node,p_node,pid_value) {
	return ary.filter((item) =>
	// 如果没有父id（第一次递归的时候）将所有父级查询出来
	// item.parentId === 0 就是最顶层
	pid_value === undefined ? (item[p_node] === 0 || item[p_node] === "") : item[p_node] === pid_value)
	.map((item) =>{
		// 通过父节点ID查询所有子节点
		item.nodes = formatSubTree(ary,c_node,p_node,item[c_node]);
		return item;
	});
}

//树形节点递归展开,父子节点id为字符串
function formatSubTreeStr(ary,c_node,p_node,pid_value) {
	return ary.filter((item) =>
	// 如果没有父id（第一次递归的时候）将所有父级查询出来
	// item.parentId === 0 就是最顶层
	pid_value === undefined ? (item[p_node].toString() === "0" || item[p_node].toString() === "") : item[p_node].toString() === pid_value.toString())
	.map((item) =>{
		// 通过父节点ID查询所有子节点
		item.nodes = formatSubTreeStr(ary,c_node,p_node,item.node_id.toString());
		return item;
	});
}
/*****************js通用函数结束***************/